package 数据库和网络;

import java.sql.*;

public class myDatebase {

    String dataBaseName;
    String USER="root";
    String URL;
    String NAME="12345SSDLh";
    Connection connection;
    public Statement statement;
    public ResultSet resultSet;

    public myDatebase(){};

    public myDatebase(String dataBaseName){
        try {this.dataBaseName=dataBaseName;
            URL="jdbc:mysql://localhost:3306/"+dataBaseName+"?useSSL=false&serverTimezone=UTC";
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection= DriverManager.getConnection(URL,USER,NAME);
            statement=connection.createStatement();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

    public void close(){
        try {
            if(this.resultSet!=null)
            this.resultSet.close();
            this.statement.close();
            this.connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }


}
